//
//  UIFont+runtime.m
//  HaiGeEr_Student
//
//  Created by liuchen on 2018/9/9.
//  Copyright © 2018年 海格尔. All rights reserved.
//
#define IS_IPHONE_6_6S_7_8 ([[UIScreen mainScreen] bounds].size.height == 667.0f)
#define IS_IPHONE_6_6S_7_8_PLUS ([[UIScreen mainScreen] bounds].size.height == 736.0f)
#define IS_IPHONE_X ([[UIScreen mainScreen] bounds].size.height == 812.0f)
// 这里设置iPhone6放大的字号数（现在是放大2号，也就是iPhone4s和iPhone5上字体为15时，iPhone6上字号为17）
#define IPHONE6_INCREMENT 2
// 这里设置iPhone6Plus放大的字号数（现在是放大3号，也就是iPhone4s和iPhone5上字体为15时，iPhone6上字号为18）
#define IPHONE6PLUS_INCREMENT 3

#import "UIFont+runtime.h"
#import <objc/runtime.h>

@implementation UIFont (runtime)
+(void)load{
    //获取替换后的类方法
    Method newMethod = class_getClassMethod([self class], @selector(adjustFont:));
    //获取替换前的类方法
    Method method = class_getClassMethod([self class], @selector(systemFontOfSize:));
    //然后交换类方法
    method_exchangeImplementations(newMethod, method);
    
    //获取替换后的类方法
    Method newMethodTwo = class_getClassMethod([self class], @selector(adjustName:size:));
    //获取替换前的类方法
    Method methodTwo = class_getClassMethod([self class], @selector(fontWithName:size:));
    //然后交换类方法
    method_exchangeImplementations(newMethodTwo, methodTwo);
    
    //获取替换后的类方法
    Method newMethodThree = class_getClassMethod([self class], @selector(adjustFontOfSize:));
    //获取替换前的类方法
    Method methodThree = class_getClassMethod([self class], @selector(boldSystemFontOfSize:));
    //然后交换类方法
    method_exchangeImplementations(newMethodThree, methodThree);
    
    
}

+(UIFont *)adjustFont:(CGFloat)fontSize{
    UIFont *newFont=nil;
    if (IS_IPHONE_6_6S_7_8){
        newFont = [UIFont adjustFont:fontSize + IPHONE6_INCREMENT];
    }else if (IS_IPHONE_6_6S_7_8_PLUS || IS_IPHONE_X){
        newFont = [UIFont adjustFont:fontSize + IPHONE6PLUS_INCREMENT];
    }else{
        newFont = [UIFont adjustFont:fontSize];
    }
    return newFont;
}

+(UIFont *)adjustName:(NSString *)fontName size:(CGFloat)fontSize{
    UIFont *newFont=nil;
    if (IS_IPHONE_6_6S_7_8){
        newFont = [UIFont adjustName:fontName size:fontSize + IPHONE6_INCREMENT];
    }else if (IS_IPHONE_6_6S_7_8_PLUS || IS_IPHONE_X){
        newFont = [UIFont adjustName:fontName size:fontSize + IPHONE6PLUS_INCREMENT];
    }else{
        newFont = [UIFont adjustName:fontName size:fontSize];
    }
    return newFont;
}

+(UIFont *)adjustFontOfSize:(CGFloat)fontSize{
    UIFont *newFont=nil;
    if (IS_IPHONE_6_6S_7_8){
        newFont = [UIFont adjustFontOfSize:fontSize + IPHONE6_INCREMENT];
    }else if (IS_IPHONE_6_6S_7_8_PLUS || IS_IPHONE_X){
        newFont = [UIFont adjustFontOfSize:fontSize + IPHONE6PLUS_INCREMENT];
    }else{
        newFont = [UIFont adjustFontOfSize:fontSize];
    }
    return newFont;
}

+ (CGFloat)returnFontSizeWithSize:(CGFloat)fontSize{
    CGFloat returnSize = 0;
    if (IS_IPHONE_6_6S_7_8){
        returnSize = fontSize + IPHONE6_INCREMENT;
    }else if (IS_IPHONE_6_6S_7_8_PLUS || IS_IPHONE_X){
        returnSize = fontSize + IPHONE6PLUS_INCREMENT;
    }else{
        returnSize = fontSize;
    }
    return returnSize;
}








@end
